package com.example.administrator.liveapp.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.CountDownTimer;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.liveapp.ApplicationUtils;
import com.example.administrator.liveapp.MainActivity;
import com.example.administrator.liveapp.R;
import com.example.administrator.liveapp.Xutils3.MyCallBack;
import com.example.administrator.liveapp.Xutils3.XUtils;
import com.example.administrator.liveapp.adapter.ArticleCommentAdapter;
import com.example.administrator.liveapp.adapter.LiveDetailCommentAdapter;
import com.example.administrator.liveapp.base.BaseRVAdapter;
import com.example.administrator.liveapp.base.BaseViewHolder;
import com.example.administrator.liveapp.bean.ArticleDetailsBean;
import com.example.administrator.liveapp.utils.AndroidBug5497Workaround;
import com.example.administrator.liveapp.utils.AppUrl;
import com.example.administrator.liveapp.utils.GlideImgManager;
import com.example.administrator.liveapp.utils.TimeChangeUtil;
import com.example.administrator.liveapp.view.FullyLinearLayoutManager;
import com.example.administrator.liveapp.view.MyWebView;
import com.example.administrator.liveapp.view.ObservableScrollView;
import com.google.gson.Gson;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * 文章详情activity
 */

public class ArticleDetailsPage extends AppCompatActivity implements View.OnClickListener {

    private String articleId;//文章Id
    private ArticleDetailsBean bean;
    private String consumerId;//用户id
    private WebView webView;
    private View loadView;//loding页面（加载页）

    /**
     * @param savedInstanceState
     */

    private NestedScrollView scroll;
    private TextView article_title;//标题
    private TextView article_author;//作者
    private TextView article_time;//发布时间
    private TextView like_number;//点攒数
    private Button article_exceptional;//打赏
    private ImageView dashang;
    private RecyclerView head_portrait;//打赏头像列表
    private RecyclerView article_comment;//用户评论
    private TextView reading;//阅读量
    private TextView like_number2;//点攒数
    private TextView text_line;
    private ImageView share;//分享
    private RelativeLayout rela_image;

    private ImageView article_praise;//文章点赞
    private TextView article_editText_content;//评论输入
//    private Button article_details_button;//发送

    private ArticleCommentAdapter articleCommentAdapter;//一级评论适配器

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ApplicationUtils applicationUtils = new ApplicationUtils();
        applicationUtils.addActivity(this);
        initView();
        data();
        LoadWebView();
    }

    //  boolean canGone = false;

    private void initView() {
        //去掉Activity上面的状态栏
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        setContentView(R.layout.activity_article_details_page);
//        AndroidBug5497Workaround.assistActivity(this);
//        onResume();//设置竖屏
//        dm = new DisplayMetrics();
//        getWindowManager().getDefaultDisplay().getMetrics(dm);
        //初始化控件
        loadView = findViewById(R.id.loadView);
        webView = (WebView) findViewById(R.id.webView);
        scroll = (NestedScrollView) findViewById(R.id.scroll);
        article_title = (TextView) findViewById(R.id.article_title);
        article_author = (TextView) findViewById(R.id.article_author);
        article_time = (TextView) findViewById(R.id.article_time);
        like_number = (TextView) findViewById(R.id.like_number);
        reading = (TextView) findViewById(R.id.reading);
        like_number2 = (TextView) findViewById(R.id.like_number2);
        article_exceptional = (Button) findViewById(R.id.article_exceptional);
        dashang = (ImageView) findViewById(R.id.dashang);
        text_line = (TextView) findViewById(R.id.text_line);
        share = (ImageView) findViewById(R.id.share);
        rela_image = (RelativeLayout) findViewById(R.id.rela_image);
        share.setOnClickListener(this);
        article_exceptional.setOnClickListener(this);
//        article_details_button = (Button) findViewById(R.id.article_details_button);
//        article_details_button.setOnClickListener(this);
        article_editText_content = (TextView) findViewById(R.id.article_editText_content);
        article_editText_content.setOnClickListener(this);
        article_praise = (ImageView) findViewById(R.id.article_praise);
        article_praise.setOnClickListener(this);
        head_portrait = (RecyclerView) findViewById(R.id.head_portrait);
        article_comment = (RecyclerView) findViewById(R.id.article_comment);
        Intent intent = getIntent();
        articleId = intent.getStringExtra("articleId");
        if (ApplicationUtils.getInstance().loginBean != null) {
            consumerId = ApplicationUtils.getInstance().loginBean.getConsumerid();
        }
    }

    int count = 0;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.article_praise://文章点赞
                if (ApplicationUtils.getInstance().loginBean != null) {
                    String urls = AppUrl.URLS + AppUrl.LikeUrl;
                    Map<String, String> maps = new HashMap<>();
                    maps.put("likeTid", "2");
                    maps.put("likeUid", consumerId);
                    maps.put("likeFid", bean.getArticle().getArticleid());
                    XUtils.Get(urls, maps, new MyCallBack<String>() {
                        @Override
                        public void onSuccess(String result) {
                            super.onSuccess(result);

                            JSONObject jsonObject = null;
                            try {
                                jsonObject = new JSONObject(result);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                            String code = jsonObject.optString("code");
                            if (code.equals("7920") || code.equals("7500")) {
                                count = 1;
                                article_praise.setImageResource(R.drawable.praise);
                            } else if (code.equals("7800")) {
                                article_praise.setImageResource(R.drawable.praise_w);
                                count = 2;
                            }
                        }

                        @Override
                        public void onError(Throwable ex, boolean isOnCallback) {
                            super.onError(ex, isOnCallback);
                            Toast.makeText(ArticleDetailsPage.this, "点赞错误", Toast.LENGTH_SHORT).show();
                        }

                        @Override
                        public void onFinished() {
                            super.onFinished();
                            int likes = Integer.parseInt(like_number.getText().toString());
                            if (count == 1) {
                                like_number.setText(likes + 1 + "");
                                like_number2.setText(likes + 1 + "");
                            } else if (count == 2) {
                                like_number.setText(likes - 1 + "");
                                like_number2.setText(likes - 1 + "");
                            }
                        }
                    });
                } else {
                    startActivity(new Intent(this,WxLoginPage.class));
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                    Toast.makeText(this, "用户未登录，请登录后点赞", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.article_exceptional://打赏
                if (ApplicationUtils.getInstance().loginBean == null) {
                    startActivity(new Intent(this,WxLoginPage.class));
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                    Toast.makeText(this, "用户未登录，请登录后打赏", Toast.LENGTH_SHORT).show();
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                View view = View.inflate(this, R.layout.reward, null);
                builder.setView(view);
                final AlertDialog show = builder.show();
                final EditText edit = (EditText) view.findViewById(R.id.edit);

                //判断edit的小数点监听
                edit.setFilters(new InputFilter[]{new InputFilter() {
                    int decimalNumber = 2;//小数点后保留位数

                    @Override
                    //source:即将输入的内容 dest：原来输入的内容
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                        String sourceContent = source.toString();
                        String lastInputContent = dest.toString();
                        //如果长度大于=6，不能输入
                        if (lastInputContent.length() >= 6) {
                            return "";
                        }

                        //如果以前的包含了.   再输入.  则返回""
                        if (lastInputContent.contains(".") && sourceContent.equals(".")) {
                            return "";
                        }

                        //验证删除等按键
                        if (TextUtils.isEmpty(sourceContent)) {
                            return "";
                        }
                        //以小数点"."开头，默认为设置为“0.”开头
                        if (sourceContent.equals(".") && lastInputContent.length() == 0) {
                            return "0.";
                        }
                        //输入“0”，默认设置为以"0."开头
                        if (sourceContent.equals("0") && lastInputContent.length() == 0) {
                            return "0.";
                        }
                        //小数点后保留两位
                        if (lastInputContent.contains(".")) {
                            int index = lastInputContent.indexOf(".");
                            if (dend - index >= decimalNumber + 1) {
                                return "";
                            }

                        }

                        return null;
                    }
                }});

                Button btn = (Button) view.findViewById(R.id.btn);
                btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String money = edit.getText().toString().trim();
                        try {
                            if (money.equals("") || Double.parseDouble(money) == 0) {
                                Toast.makeText(ArticleDetailsPage.this, "请输入正确金额", Toast.LENGTH_SHORT).show();
                                return;
                            }
                            upReward(money, show);
                        } catch (Exception e) {
                            Toast.makeText(ArticleDetailsPage.this, "请输入正确金额", Toast.LENGTH_SHORT).show();
                        }

                    }
                });
//
                break;
            case R.id.article_editText_content://评论弹窗
                showPopupWindow();
                break;
            case R.id.share://文章分享
                UMWeb web = new UMWeb(AppUrl.URL + "index.php/ban/index/article.html?id=" + articleId);
                if(!bean.getArticle().getArticleimgurl().equals("")){
                    String Url = bean.getArticle().getArticleimgurl();
                    UMImage image = new UMImage(ArticleDetailsPage.this, AppUrl.URL + Url);//资源文件
                    UMImage thumb = new UMImage(this, AppUrl.URL + Url);
                    image.setThumb(thumb);
                    web.setThumb(thumb);  //缩略图
                }
                web.setTitle(bean.getArticle().getArticletitle());//标题
                web.setDescription(bean.getArticle().getArticledescribe());//描述

                //带面板文本分享
                new ShareAction(ArticleDetailsPage.this)
                        .withMedia(web)
                        .setDisplayList(SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.WEIXIN ,SHARE_MEDIA.SINA, SHARE_MEDIA.QQ)
                        .setCallback(shareListener)
                        .open();
                break;
        }

    }

    private PopupWindow mPopWindow;

    private void showPopupWindow() {
        //设置contentView
        View contentView = LayoutInflater.from(ArticleDetailsPage.this).inflate(R.layout.activity_comments, null);
        mPopWindow = new PopupWindow(contentView,
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        mPopWindow.setContentView(contentView);
        mPopWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        mPopWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        final EditText comment = (EditText) contentView.findViewById(R.id.comment);
        Button article_details_button = (Button) contentView.findViewById(R.id.article_details_button);
        InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        //这里给它设置了弹出的时间，
        imm.toggleSoftInput(100, InputMethodManager.HIDE_NOT_ALWAYS);
        //设置各个控件的点击响应
        article_details_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (consumerId != null && !consumerId.equals("")) {
                    if (TextUtils.isEmpty(comment.getText())) {
                        Toast.makeText(getApplicationContext(), "评论不能为空", Toast.LENGTH_SHORT).show();
                    } else {
                        String url = AppUrl.URLS + AppUrl.CommentariesURL;
                        Map<String, String> map = new HashMap<>();
                        map.put("commentUid", consumerId);
                        map.put("commentFid", bean.getArticle().getArticleid());
                        map.put("commentTid", "2");
                        map.put("commentContent", comment.getText().toString());
                        Log.e("---", comment.getText().toString());
                        XUtils.Get(url, map, new MyCallBack<String>() {
                            @Override
                            public void onSuccess(String result) {
                                super.onSuccess(result);
                                try {
                                    JSONObject json = new JSONObject(result);
                                    String code = json.optString("code");
                                    if (code.equals("7000")) {
                                        Toast.makeText(ArticleDetailsPage.this, "评论成功", Toast.LENGTH_SHORT).show();
                                        comment.setText("");
                                        mPopWindow.dismiss();
                                    } else {
                                        Toast.makeText(ArticleDetailsPage.this, code + "评论失败", Toast.LENGTH_SHORT).show();
                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                            }

                            @Override
                            public void onError(Throwable ex, boolean isOnCallback) {
                                super.onError(ex, isOnCallback);
                                Toast.makeText(ArticleDetailsPage.this, ex.getMessage() + "", Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onFinished() {
                                super.onFinished();
                                article_editText_content.setText("");
                                data();
                                //关闭软键盘
                                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                            }
                        });
                    }
                } else {
                    startActivity(new Intent(ArticleDetailsPage.this,WxLoginPage.class));
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                    Toast.makeText(ArticleDetailsPage.this, "用户未登录，请登录后评论", Toast.LENGTH_SHORT).show();
                }
            }
        });
        //显示PopupWindow
        View rootview = LayoutInflater.from(ArticleDetailsPage.this).inflate(R.layout.activity_article_details_page, null);
        showPopmenu(rootview);
    }

    private void showPopmenu(View rootview) {
        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });
        // 显示窗口位置
        mPopWindow.showAtLocation(rootview, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        // 设置layout在PopupWindow中显示的位置
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 0.4f;
        getWindow().setAttributes(lp);
    }

    private void upReward(String money, final AlertDialog show) {
        String url = AppUrl.URL + AppUrl.payUrl;
        Map<String, String> map = new HashMap<>();
        // 微信
        if (money.substring(money.length() - 1, money.length()).equals(".")) {
            money += "0";
        }
        StringBuffer sb = new StringBuffer("{");
        sb.append("\"pay\":\"" + Double.parseDouble(money) + "\",");
        sb.append("\"ex_man\":\"" + ApplicationUtils.getInstance().loginBean.getConsumerid() + "\",");
        sb.append("\"artId\":\"" + articleId + "\"}");

        Log.e("----", sb.toString());

        //  map.put("reward", sb.toString());
        map.put("pay", Double.parseDouble(money) + "");
        map.put("ex_man", ApplicationUtils.getInstance().loginBean.getConsumerid() + "");
        map.put("artId", articleId + "");
        map.put("body", "赞赏");
        XUtils.Get(url, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.e("----", result);
                JSONObject obj = null;
                try {
                    obj = new JSONObject(result);
                    // 微信支付回调
                    setWeChat(obj);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                show.cancel();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);

            }

            @Override
            public void onFinished() {
                super.onFinished();

            }
        });

    }

    //支付
    private IWXAPI mIwxapi;

    /**
     * 微信支付
     */
    private void setWeChat(JSONObject obj) {
        mIwxapi = WXAPIFactory.createWXAPI(this, obj.optString("appid"));
        mIwxapi.registerApp(obj.optString("appid"));// 将应用注册到微信
        if (mIwxapi != null && mIwxapi.isWXAppInstalled()) {// 判断用户有没有安装微信
            PayReq req = new PayReq();
            req.appId = obj.optString("appid");
            req.partnerId = obj.optString("partnerid");
            req.prepayId = obj.optString("prepayid");
            req.nonceStr = obj.optString("noncestr");
            req.timeStamp = obj.optString("timestamp");
            req.packageValue = obj.optString("package");
            req.sign = obj.optString("sign");
            // req.extData = "app data";// 可选
            mIwxapi.sendReq(req);
        } else {
            Toast.makeText(this, "用户未安装微信", Toast.LENGTH_SHORT).show();
            return;
        }
    }

    /**
     * 隐藏虚拟按键，并且全屏
     */
//    protected void hideBottomUIMenu() {
//        //隐藏虚拟按键，并且全屏
//        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
//            View v = this.getWindow().getDecorView();
//            v.setSystemUiVisibility(View.GONE);
//        } else if (Build.VERSION.SDK_INT >= 19) {
//            //for new api versions.
//            View decorView = getWindow().getDecorView();
//            int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
//                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
//            decorView.setSystemUiVisibility(uiOptions);
//        }
//    }

    /**
     * 文章详情页数据请求
     */
    private void data() {
        String url = AppUrl.URL + AppUrl.ArticleDetailsURL;
        Map<String, String> map = new HashMap<>();
        map.put("articleId", articleId);
        if (consumerId != null && !consumerId.equals("")) {
            map.put("consumerId", consumerId);
        }else{
            article_exceptional.setVisibility(View.GONE);
            dashang.setVisibility(View.GONE);
            rela_image.setVisibility(View.GONE);
        }
        XUtils.Get(url, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(result);
                    String code = jsonObject.optString("code");
                    if (code.equals("40000")) {
                        Gson gson = new Gson();
                        bean = gson.fromJson(result, ArticleDetailsBean.class);
                        article_title.setText(bean.getArticle().getArticletitle());
                        article_author.setText(bean.getArticle().getArticleauthor());
                        article_time.setText(TimeChangeUtil.getStrTime2(bean.getArticle().getArticletime()));
                        like_number.setText(bean.getArticle().getArticlebestcount());
                        reading.setText("阅读 " + bean.getArticle().getArticleviewcount());
                        like_number2.setText(bean.getArticle().getArticlebestcount());
                        if (bean.getArticle().getArticleLikeStatics().equals("1")) {
                            article_praise.setImageResource(R.drawable.praise);
                        } else {
                            article_praise.setImageResource(R.drawable.praise_w);
                        }
                        if (consumerId != null && !consumerId.equals("")) {
                            if(bean.getArticle().getIf_contract().equals("1")&&bean.getArticle().getIs_reward().equals("1")){
                                article_exceptional.setVisibility(View.VISIBLE);
                                dashang.setVisibility(View.VISIBLE);
                                rela_image.setVisibility(View.VISIBLE);
                            }else{
                                article_exceptional.setVisibility(View.GONE);
                                dashang.setVisibility(View.GONE);
                                rela_image.setVisibility(View.GONE);
                            }
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    Toast.makeText(ArticleDetailsPage.this, e.getMessage()+"", Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
            }

            @Override
            public void onFinished() {
                super.onFinished();
                if(bean.getComment().size()==0){
                    text_line.setText("当前还没有用户评论");
                }else{
                    text_line.setVisibility(View.GONE);
                }
                //一级评论
                FullyLinearLayoutManager mLinearLayoutManager = new FullyLinearLayoutManager(ArticleDetailsPage.this);
                mLinearLayoutManager.setScrollEnabled(false);
                article_comment.setLayoutManager(mLinearLayoutManager);
                article_comment.setHasFixedSize(true);
                article_comment.setNestedScrollingEnabled(false);
                articleCommentAdapter = new ArticleCommentAdapter(bean.getComment());
                article_comment.setAdapter(articleCommentAdapter);
                //打赏头像
                reward();
            }
        });
    }

    private void reward() {
        FullyLinearLayoutManager mLinearLayoutManager = new FullyLinearLayoutManager(ArticleDetailsPage.this);
        mLinearLayoutManager.setScrollEnabled(true);
        mLinearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        head_portrait.setLayoutManager(mLinearLayoutManager);
        head_portrait.setHasFixedSize(true);
        head_portrait.setAdapter(new BaseRVAdapter(ArticleDetailsPage.this, bean.getReward()) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.head_reward;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {

                if (bean.getReward().get(position) != null && !bean.getReward().get(position).equals("")) {
                    String str = bean.getReward().get(position);
                    String photo = str.substring(0, 4);
                    if (photo.equals("http")) {
                        GlideImgManager.glideLoader(ArticleDetailsPage.this, bean.getReward().get(position), R.mipmap.consumer, R.mipmap.consumer, holder.getImageView(R.id.head_portrait), 0);//Glide圆形图片工具类
                    } else {
                        GlideImgManager.glideLoader(ArticleDetailsPage.this, AppUrl.URLS + bean.getReward().get(position), R.mipmap.consumer, R.mipmap.consumer, holder.getImageView(R.id.head_portrait), 0);//Glide圆形图片工具类
                    }
                }
            }

        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        data();
    }

    String webUrl;

    private void LoadWebView() {
        // 设置支持javascript
        webView.getSettings().setJavaScriptEnabled(true);

        webView.getSettings().setAppCacheEnabled(true);

        webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

        //自适应屏幕
//        webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//        webView.getSettings().setLoadWithOverviewMode(true);

        // 开启 localStorage
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setDefaultTextEncodingName("utf-8");
        // 设置缓存模式
        webView.requestFocus();
        webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
        Log.e("article====", "http://www.bsf.ink/index.php/ban/index/article_mobile?id=" + articleId);
        webUrl = AppUrl.URL + "index.php/ban/index/article_mobile?id=" + articleId;//type是为了区分APP传参和web页面传参
        webView.loadUrl(webUrl);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                loadView.setVisibility(View.GONE);
            }

            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }
        });
    }


    private UMShareListener shareListener = new UMShareListener() {
        /**
         * @descrption 分享开始的回调
         * @param platform 平台类型
         */
        @Override
        public void onStart(SHARE_MEDIA platform) {

        }

        /**
         * @descrption 分享成功的回调
         * @param platform 平台类型
         */
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(ArticleDetailsPage.this, "分享成功", Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享失败的回调
         * @param platform 平台类型
         * @param t 错误原因
         */
        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(ArticleDetailsPage.this, "分享失败" + t.getMessage(), Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享取消的回调
         * @param platform 平台类型
         */
        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(ArticleDetailsPage.this, "分享取消", Toast.LENGTH_LONG).show();

        }
    };

    /**
     * 分享是否同意的回调
     *
     * @param requestCode
     * @param permissions
     * @param grantResults
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {

    }
}

